package fun.shuofeng.juc.reentranlock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo02 {
    public static final ReentrantLock LOCK = new ReentrantLock();

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            System.out.println("t1 线程启动");
            try {
                LOCK.lockInterruptibly();
            } catch (InterruptedException e) {
                System.out.println("等待过程中被打断");
                e.printStackTrace();
                return;
            }
            try {
                System.out.println("t1 获得可打断锁");
            } finally {
                LOCK.unlock();
            }
        }, "t1");

        LOCK.lock();
        System.out.println("main 获得锁");
        thread.start();

        TimeUnit.SECONDS.sleep(2);
        System.out.println("执行打断");
        thread.interrupt();

    }
}
